﻿using System;
using System.Linq;
using System.Web.Mvc;
using Icms.Core;
using Icms.Core.Model;
using Icms.Core.Service;
using Icms.WebUI.Builder;
using Icms.WebUI.Dto;
using Omu.Awesome.Mvc;

namespace Icms.WebUI.Controllers
{
    public class HearingController : Cruder<Hearing, HearingInput>
    {
        private new readonly IHearingService s;

        public HearingController(IMapper<Hearing, HearingInput> v, IHearingService s)
            : base(s, v)
        {
            this.s = s;
        }

        public virtual ActionResult Search(string title, Guid caseId, int page = 1, int ps = 5)
        {
            var src = s.Where(o => o.CaseId == caseId);
            var rows = this.RenderView("rows", src.Pag(page, ps));

            return Json(new { rows, more = src.Count() > page * ps });
        }

        public override ActionResult Index()
        {
            ViewBag.Case = new Guid(Request["CaseId"]).Case();
            return View();
        }

        public ActionResult Calendar(Guid CaseId)
        {
            ViewBag.CaseId = CaseId;
            return View();
        }
    }
}